#include "PrecompiledHeader.h"
#include "Globals.h"

/*--------------------------------------------------------------------------*/

std::string GetFileName(const std::string& path)
{
	std::string filefullname = ::GetFileFullname(path);
	uint pathlength = filefullname.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (filefullname[i] == '.')
		{
			return filefullname.substr(0, i);
		}
	}

	return filefullname;
}

/*--------------------------------------------------------------------------*/

std::string GetFileExt(const std::string& path)
{
	std::string filefullname = ::GetFileFullname(path);
	uint pathlength = filefullname.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (filefullname[i] == '.')
		{
			return filefullname.substr(i, filefullname.length());
		}
	}

	return "";
}

/*--------------------------------------------------------------------------*/

std::string GetFileFullname(const std::string& path)
{
	std::string temp;
	uint pathlength = path.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (path[i] != '/' && path[i] != '\\')
		{
			temp += path[i];
		}
		else
		{
			temp = "";
		}
	}

	return temp;
}

/*--------------------------------------------------------------------------*/

std::string GetFilePath(const std::string& path)
{
	std::string toreturn, temp;
	uint pathlength = path.length();

	for (uint i = 0; i < pathlength; ++i)
	{
		if (path[i] != '/')
		{
			temp += path[i];
		}
		else
		{
			toreturn += temp + "/";
			temp = "";
		}
	}

	return toreturn;
}

/*--------------------------------------------------------------------------*/

// GLenum StrToEnum(const std::string& c)
// {
// 	static std::map<const std::string, int> retVal = std::map<const std::string, int>();
// 	static bool initialized = false;
//
// 	if (initialized == false)
// 	{
// 		initialized = true;
//
// 		retVal["NULL"] =					-1;
// 		retVal["ColorAndDepth"] =			ERenderTaskType::ColorAndDepth;
// 		retVal["UserInterface"] =			ERenderTaskType::UserInterface;
// 		retVal["LightSource"] =				ERenderTaskType::LightSource;
// 		retVal["PostProcessing"] =			ERenderTaskType::PostProcessing;
// 		retVal["Finally"] =					ERenderTaskType::Finally;
// 		retVal["ColorAndDepthParticles"] =	ERenderTaskType::ColorAndDepthParticles;
// 		retVal["Blending"] =				ERenderTaskType::Blending;
// 		retVal["AfterDS"] =					ERenderTaskType::AfterDS;
// 		retVal["TypeCount"] =				ERenderTaskType::TypeCount;
// 	}
//
// 	std::map<const std::string, int>::iterator iter = retVal.find(c);
// 	AssertLogE(iter == retVal.end(), "Error - %s not found.", c.c_str());
//
// 	return retVal[c];
// }

/*--------------------------------------------------------------------------*/

float RandFloat(float min, float max)
{
	static float inv_rand_max = 1.0f / (float) RAND_MAX;
	return min + ((rand() * inv_rand_max) * (max - min));
}

/*--------------------------------------------------------------------------*/

int RandInt(int min, int max)
{
	return min + rand() % (max - min);
}

/*--------------------------------------------------------------------------*/